package com.sign.webview;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.widget.ImageView;

public class Main2Activity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ImageView imageView = findViewById(R.id.image);
        String url = getIntent().getStringExtra("url");
        imageView.setImageBitmap(stringtoBitmap(Stringbehind(url,"data:image/png;base64,")));//截取data:image/png;base64
    }
    public static String Stringbehind(String content, String string) {
        //截取之后的字符
        int length = string.length();
        String str = content.substring(content.indexOf(string));
        return str.substring(length);
    }
    public Bitmap stringtoBitmap(String string) {
        //将字符串转换成Bitmap类型
        Bitmap bitmap = null;
        try {
            byte[] bitmapArray;
            bitmapArray = Base64.decode(string, Base64.DEFAULT);
            bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("xhx", "base64转换图片异常");
        }

        return bitmap;
    }
}
